package com.vanke.devops.domain.domain.docker.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.vanke.devops.dal.dao.SwarmClusterMapper;
import com.vanke.devops.dal.model.SwarmCluster;
import com.vanke.devops.domain.base.BaseServiceImpl;
import com.vanke.devops.domain.domain.docker.ISwarmClusterService;
import com.vanke.devops.domain.domain.docker.dto.SwarmClusterDTO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户表  服务实现类
 * </p>
 *
 * @author 陈景阳
 * @since 2018-06-07
 */
@Service
public class SwarmClusterServiceImpl extends BaseServiceImpl<SwarmClusterMapper, SwarmCluster> implements ISwarmClusterService {

    @Override
    public SwarmClusterDTO add(String name, String leader,String remark) {
        SwarmCluster entity = new SwarmCluster();
        entity.setLeader(leader);
        entity.setName(name);
        entity.setRemark(remark);
        super.add(entity);
        return getInfo(entity.getId());
    }

    @Override
    public SwarmClusterDTO getInfo(Integer id) {
        SwarmCluster entity = super.queryById(id);
        return getSwarmClusterDTO(entity);
    }

    @Override
    public List<SwarmClusterDTO> list() {
        List<SwarmCluster> list = baseMapper.selectList(new EntityWrapper<>());
        return list.stream().map(this::getSwarmClusterDTO).collect(Collectors.toList());
    }

    private SwarmClusterDTO getSwarmClusterDTO(SwarmCluster entity){
        SwarmClusterDTO dto = new SwarmClusterDTO();
        dto.setId(entity.getId());
        dto.setLeader(entity.getLeader());
        dto.setName(entity.getName());
        dto.setRemark(entity.getRemark());
        return dto;
    }
}